package ssi.staaar;

import ssi.staar.R;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

public class SettingsActivity extends Activity {
	private SharedPreferences pref;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.settings);
		Log.d("[SETTINGS]", "Started");
		pref = getSharedPreferences(Staaar.PREFS_NAME, 0);
		EditText meters = (EditText)findViewById(R.id.updateMeterEdit);
		EditText minutes = (EditText)findViewById(R.id.updateMinuteEdit);
		EditText radius = (EditText)findViewById(R.id.updateRadiusMetersEdit);
		float minMeters = pref.getFloat("MinMeters", Staaar.DEFAULT_METERS);
		long minMinutes = (pref.getLong("MinMinutes", Staaar.DEFAULT_MINUTES)/(1000*60));
		float radiusMeters = pref.getFloat("RadiusMeters", Staaar.DEFAULT_RADIUS_METERS);
		meters.setText(Integer.toString(Math.round(minMeters)));
		minutes.setText(Long.toString(minMinutes));
		radius.setText(Integer.toString(Math.round(radiusMeters)));
	}
	
	public void confirmSettings(View v) {
		EditText meters = (EditText)findViewById(R.id.updateMeterEdit);
		EditText minutes = (EditText)findViewById(R.id.updateMinuteEdit);
		EditText radius = (EditText)findViewById(R.id.updateRadiusMetersEdit);
		Editor edit = pref.edit();
		edit.putFloat("MinMeters", Float.parseFloat(meters.getText().toString()));
		edit.putLong("MinMinutes", (Integer.parseInt((minutes.getText().toString())))*1000*60);
		edit.putFloat("RadiusMeters", Float.parseFloat(radius.getText().toString()));
		edit.commit();
		finish();
	}
}
